import 'package:flutter/material.dart';
import 'package:flutter_hi_cache/flutter_hi_cache.dart';
import 'package:imooc_flutter_2024/dao/login_dao.dart';
import 'package:imooc_flutter_2024/navigator/tab_navigator.dart';
import 'package:imooc_flutter_2024/pages/home_page.dart';
import 'package:imooc_flutter_2024/pages/login_page.dart';
import 'package:imooc_flutter_2024/util/screen_adapter_helper.dart';

void main() {
  runApp(const MainApp());
}

class MainApp extends StatelessWidget {
  const MainApp({super.key});

  @override
  Widget build(BuildContext context) {
    // Future<dynamic>? future = _initializeApp();
    ScreenHelper.init(context);
    return MaterialApp(
        home: FutureBuilder(
            future: HiCache.preInit(),
            builder: (context, snapshot) {
              if (snapshot.connectionState == ConnectionState.done) {
                if (LoginDao.getBoardingPass() != null) {
                  return TabNavigator();
                } else {
                  return LoginPage();
                }
              } else {
                return const Scaffold(
                  body: Center(
                    child: CircularProgressIndicator(),
                  ),
                );
              }
            }));
  }
}
